package com.qf.mapper;

import com.qf.model.User;
import org.apache.ibatis.annotations.*;
import java.util.List;


@Mapper
public interface UserMapper {
    @Select("select * from user where status=1")
    List<User> selectAll();

    @Results(id = "userMap",value = {
                @Result(column = "id",property = "id"),
                @Result(column = "username",property = "username"),
                @Result(column = "password",property = "password"),
                @Result(column = "nickname",property = "nickname"),
                @Result(column = "phone",property = "phone"),
                @Result(column = "email",property = "email"),
                @Result(column = "birthday",property = "birthday"),
                @Result(column = "sex",property = "sex"),
                @Result(column = "createtime",property = "createtime"),
                @Result(column = "updatetime",property = "updatetime")
})

    @Select("select * from user where status =1 limit #{currentPage},#{pageSize}")
    List<User> findPage(@Param("currentPage")Integer currentPage,@Param("pageSize")Integer pageSize);

    @Select("select count(*) from user where status =1")
    Long count();

    @Insert("insert into user (username,password,nickname,phone,email,birthday,sex,createtime,updatetime) " +
            "values (#{username},#{password},#{nickname},#{phone},#{email},#{birthday},#{sex},#{createtime},#{updatetime})")
    int insertUser(User user);

    @Select("select * from user where id =#{id} and status=1")
    @ResultMap("userMap")
    User findById(int id);
    @Update("update user set username=#{username},nickname=#{nickname},phone=#{phone},email=#{email},birthday=#{birthday},sex=#{sex},createtime=#{createtime},updatetime=#{updatetime} where id=#{id} and status=1")
    int update(User user);
    @Update("update user set status =0 where id=#{id}")
    int delById(Integer id);

    @Select("select * from user where username=#{username} and status=1")
    User findByUsername(String username);

}
